home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD88728112000.psc / ZyWeb Beta / basMain.bas next >
Encoding:
BASIC Source File  |  2000-08-05  |  2.9 KB  |  104 lines

  1. Attribute VB_Name = "basMain"
  2. Option Explicit
  3.  
  4. '-------------
  5. 'API Declares.
  6. '=============
  7.  
  8. Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  9. Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
  10. Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
  11. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  12.  
  13. '--------------
  14. 'API Constants.
  15. '==============
  16.  
  17. 'Used for Hooking into the key board.
  18. Public Const WH_KEYBOARD = 2
  19.  
  20. 'Find a string.
  21. Public Const CB_FINDSTRING = &H14C
  22.  
  23. '-----------------
  24. 'Public variables.
  25. '=================
  26.  
  27. 'Used for the windows hook.
  28. Public hHook As Long
  29.  
  30. 'Used to track the last key pressed.
  31. Public LastKeyPressed As Long
  32. '
  33. 'Used to handle keys pressed before windows gets to them.
  34. '
  35. Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  36.     If nCode >= 0 Then
  37.         KeyboardProc = 1
  38.         LastKeyPressed = wParam
  39.     End If
  40.     KeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)
  41. End Function
  42. Public Function AutoComplete(cbo As ComboBox) As Boolean
  43.     
  44.     Dim sText As String
  45.     Dim lIndex As Long
  46.     Static iLen As Integer
  47.     
  48.     With cbo
  49.         
  50.         'Check if backspace was pressed.
  51.         If LastKeyPressed = 8 Then
  52.         
  53.             'Backspace pressed so
  54.             'strip off the last letter
  55.             'of the combo text.
  56.             If iLen = 0 Then iLen = 1
  57.             .Text = Left$(.Text, iLen - 1)
  58.         
  59.         End If
  60.         
  61.         'Check if delete was pressed.
  62.         If LastKeyPressed = 46 Then
  63.             
  64.             'Just exit and let
  65.             'the delete go ahead.
  66.             Exit Function
  67.             
  68.         End If
  69.         
  70.         sText = .Text
  71.         iLen = Len(.Text)
  72.         
  73.         'Used the SendMessage API for a fast search of the combo.
  74.         lIndex = SendMessage(.hwnd, CB_FINDSTRING, -1, ByVal .Text)
  75.     
  76.         'Check if a match if found.
  77.         If lIndex >= 0 Then
  78.             
  79.             'If so, select it.
  80.             .ListIndex = lIndex
  81.             
  82.             'set the highlight text to
  83.             'the auto completed section.
  84.             .SelStart = iLen
  85.             .SelLength = Len(.List(.ListIndex)) - iLen
  86.             
  87.             'Set the function to true.
  88.             AutoComplete = True
  89.     
  90.         Else
  91.             
  92.             'Select nothing.
  93.             .ListIndex = -1
  94.             
  95.             'Set the function to false.
  96.             AutoComplete = False
  97.     
  98.         End If
  99.         
  100.     End With
  101.     
  102. End Function
  103.  
  104.